package com.example.crm.service.Impl;

import com.example.crm.dao.ICustomerDAO;
import com.example.crm.dao.Impl.CustomerDAOImpl;
import com.example.crm.pojo.Customer;
import com.example.crm.service.ICustomerService;

import java.sql.SQLException;
import java.util.List;

public class CustomerServiceImpl implements ICustomerService {
    ICustomerDAO CustomerDAO = new CustomerDAOImpl();
    @Override
    public boolean add(Customer c) {
        try {
            return CustomerDAO.insert(c)>0;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return false;
    }

    @Override
    public List<Customer> find() {
        List<Customer> list = null;
        try {
            list = CustomerDAO.find();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return list;
    }

    @Override
    public boolean delete(long custId) {
        try {
            int result = CustomerDAO.delete(custId);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return false;
    }

    @Override
    public Customer findById(long custId) {
        Customer customer = null;
        try {
            customer = CustomerDAO.findById(custId);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return customer;
    }

    @Override
    public boolean update(Customer c) {
        try {
           int result = CustomerDAO.update(c);
           return result>0;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return false;
    }
}
